<template>
    <div class="app-container">
        <div v-if="opt != 'add'">
            <el-descriptions title="">
                <el-descriptions-item label="序号">
                    <el-tag size="medium">{{ obj != null ? obj.index : index }}</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="项目信息" name="first">
                <el-form :model="form" ref="form" :rules="rules" label-width="100px">
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="项目编号" prop="projectNumber" label-width="110px">
                                <el-input v-model="form.projectNumber" placeholder="请输入项目编号" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="项目名称" prop="projectName" label-width="110px">
                                <el-input v-model="form.projectName" placeholder="请输入项目名称" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="项目负责人" prop="projectLeader" label-width="110px">
                                <el-input v-model="form.projectLeader" disabled="disabled" placeholder="请选择项目负责人" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="执行人" prop="executorName" label-width="110px">
                                <el-input v-model="form.executorName" :disabled="opt == 'mainView'"
                                    placeholder="请选择项目执行人" @focus="selectOpen(5)" :readonly="readonly" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="预算总额" prop="budgetAmount" label-width="110px">
                                <el-input v-model="form.budgetAmount" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="计划开始时间" prop="startTime" label-width="110px">
                                <el-input v-model="form.startTime" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="计划结束时间" prop="endTime" label-width="110px">
                                <el-input v-model="form.endTime" disabled="disabled" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8" style="height: 55px;">
                            <el-form-item label="阶段" prop="projectStage" label-width="110px">
                                <el-input v-model="form.projectStage" placeholder="请选择阶段" :readonly="readonly"
                                    @focus="selectStage(1)" style="width:703px;" :disabled="opt == 'mainView'" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row style="margin: 10px -10px 12px 40px;width:1050px">
                        <el-row :gutter="10" class="mb8">
                            <el-col :span="1.5">
                                <span style="font-size: 14px;margin: 0px 5px 0px 520px;">收款方式 </span>&nbsp;&nbsp;
                            </el-col>
                        </el-row>
                        <el-table :data="tableData" size="mini">
                            <el-table-column label="序号" type="index" align="center" prop="indexTwo" />
                            <el-table-column prop="paymentName" label="款项名称" min-width="120" align="center">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.paymentName" disabled="disabled" />
                                </template>
                            </el-table-column>
                            <el-table-column prop="amountCollected" label="收款金额" min-width="80" align="center">

                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.amountCollected" disabled="disabled" />
                                </template>
                            </el-table-column>
                            <el-table-column prop="estimatedCollectionTime" label="预计收款时间" min-width="72"
                                align="center">

                                <template slot-scope="scope">
                                    <el-date-picker clearable v-model="scope.row.estimatedCollectionTime" type="date"
                                        value-format="yyyy-MM-dd" :picker-options="{ disabledDate: dateOptions }"
                                        placeholder="请选择预计收款时间" disabled="disabled">
                                    </el-date-picker>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                    <el-row style="margin: 10px -0px 12px 40px;">
                        <el-row :gutter="10" class="mb8" v-if="isDel">
                            <el-col :span="1.5">
                                <span style="font-size: 14px;margin-left: 520px;">子项目信息</span>&nbsp;&nbsp;&nbsp;&nbsp;
                                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addSubProject"
                                    style="text-align: center;" v-if="isSave"></el-button>
                            </el-col>
                        </el-row>
                        <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange"
                            highlight-current-row>
                            <el-table-column label="项目编号" align="center" prop="projectNumber" />
                            <el-table-column label="项目名称" align="center" prop="projectName" width="180" />
                            <el-table-column label="产品名称" align="center" prop="productName" />
                            <el-table-column label="外协公司" align="center" prop="outsourcingCompany" width="180" />
                            <el-table-column label="阶段" align="center" prop="subProjectStage" width="140"
                                :show-overflow-tooltip="true" />
                            <el-table-column label="执行人" align="center" prop="executorName" width="70" />
                            <el-table-column label="费用" align="center" prop="cost" />
                            <el-table-column label="类型" align="center" prop="type" width="50">

                                <template slot-scope="scope">
                                    <dict-tag :options="dict.type.sub_project_type" :value="scope.row.type" />
                                </template>
                            </el-table-column>
                            <el-table-column label="计划开始时间" align="center" prop="startTime" width="120">

                                <template slot-scope="scope">
                                    <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="计划结束时间" align="center" prop="endTime" width="120">

                                <template slot-scope="scope">
                                    <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="60"
                                v-if="isSave">

                                <template slot-scope="scope">
                                    <el-button size="mini" type="text" icon="el-icon-delete"
                                        @click="handleDeleteSub(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                </el-form>
                <div style="text-align: center;">
                    <el-button type="primary" @click="submitForm" v-if="isSave">保 存</el-button>
                    <el-button @click="cancel">关 闭</el-button>
                </div>
            </el-tab-pane>
            <el-tab-pane label="产品信息" name="second">
                <div style="text-align: center;">
                    <el-row style="margin: 25px 0px 25px 0px;">产品列表</el-row>
                    <el-table height="400" v-loading="loading" :data="productInfoList">
                        <el-table-column label="产品类型" align="center" prop="productCategory">

                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.product_type" :value="scope.row.productCategory" />
                            </template>
                        </el-table-column>
                        <el-table-column label="产品编号" align="center" prop="productNumber" />
                        <el-table-column label="产品名称" align="center" prop="productName" />
                        <el-table-column label="费用" align="center" prop="pricingRange" />
                    </el-table>
                    <pagination v-show="total > 0" :total="total" :page.sync="queryProductParams.pageNum"
                        :limit.sync="queryProductParams.pageSize" @pagination="getProjectProductList" />
                    <div style="text-align: center;margin-top: 15px;">
                        <el-button @click="cancel">关 闭</el-button>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="评审信息" name="third" :disabled="isReview">
                <div style="text-align: center;">
                    <div>
                        <el-form ref="formReview" :model="formReview" :inline="true" :rules="reviewRules"
                            v-if="reviewView">
                            <el-row style="line-height: 2px;">
                                <el-col :span="8" style="margin-left: 180px;">
                                    <el-form-item label="评审结果" prop="reviewResult" label-width="90px">

                                        <template>
                                            <el-radio-group v-model="formReview.reviewResult" :disabled="isOpt"
                                                @change="changeReviewComments">
                                                <el-radio :label="0">同意</el-radio>
                                                <el-radio :label="1">退回</el-radio>
                                                <el-radio :label="2">办结</el-radio>
                                                <el-radio :label="3">终止</el-radio>
                                            </el-radio-group>
                                        </template>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="7" style="height: 20px;width: 33%;">
                                    <el-form-item label="评审人" prop="reviewer" label-width="100px"
                                        v-if="formReview.reviewResult === 0">
                                        <el-input v-model="formReview.reviewer" placeholder="请选择评审人" readonly="readonly"
                                            style="width: 207px;" />
                                    </el-form-item>
                                    <el-input v-model="formReview.reviewerId" type="hidden" />
                                </el-col>
                                <el-col :span="1">
                                    <el-button style="margin-left: -20px;" type="primary" @click="selectReviewUser"
                                        v-if="isSelect && formReview.reviewResult === 0">选择</el-button>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col>
                                    <el-form-item label="评审意见" prop="reviewComments" label-width="110px">
                                        <el-input v-model="formReview.reviewComments" type="textarea"
                                            placeholder="请输入内容" :rows="4" :disabled="isOpt"
                                            style="width: 657px;margin-right: 100px;" />
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                        <el-row>
                            <el-table v-loading="loading" :data="reviewList">
                                <el-table-column label="评审人" align="center" prop="reviewer" width="180" />
                                <el-table-column label="评审结果" align="center" prop="reviewResult" width="180">

                                    <template slot-scope="scope">
                                        <dict-tag :options="dict.type.contract_review_result"
                                            :value="scope.row.reviewResult" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="评审意见" align="center" prop="reviewComments" />
                                <el-table-column label="评审时间" align="center" prop="reviewTime" width="180">

                                    <template slot-scope="scope">
                                        <span>{{ parseTime(scope.row.reviewTime, '{y}-{m}-{d}') }}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-row>
                        <div style="text-align: center;margin-top: 15px;">
                            <el-button type="primary" @click="submitReviewForm" v-if="isShowButton">保 存</el-button>
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="预算明细" name="four">
                <div style="text-align: center;">
                    <div>
                        <el-row :gutter="10" class="mb8" v-if="isDel">
                            <el-col :span="1.5">
                                <span style="font-size: 14px;margin-left: 520px;">预算费用</span>&nbsp;&nbsp;&nbsp;&nbsp;
                                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addBudgetInfo"
                                    style="text-align: center;" v-if="isSave"></el-button>
                            </el-col>
                        </el-row>
                        <el-table v-loading="loading" :data="budgetList" border>
                            <el-table-column label="序号" type="index" align="center" prop="index" :index="indexMethod" />
                            <el-table-column label="费用条目" align="center" prop="expenseName" />
                            <el-table-column label="预算金额" align="center" prop="expenseAmount" width="300" />
                            <el-table-column label="操作" align="center" class-name="small-padding fixed-width"
                                width="100" v-if="isSave">

                                <template slot-scope="scope">
                                    <el-button size="mini" type="text" icon="el-icon-delete"
                                        @click="handleDeleteBudget(scope.row)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div style="text-align: center;margin-top: 15px;">
                            <el-button @click="cancel">关 闭</el-button>
                        </div>
                    </div>
                </div>
            </el-tab-pane>

        </el-tabs>
        <select-user ref="select" :type="userType" :sign="sign" @ok="selectUser"></select-user>
        <!-- 添加或修改【请填写功能名称】对话框 -->
        <el-dialog title="添加预算费用" :visible.sync="openBudget" width="500px" append-to-body>
            <el-form ref="formBudget" :model="formBudget" :rules="rulesBudget" label-width="80px">
                <el-form-item label="费用条目" prop="expenseName">
                    <el-input v-model="formBudget.expenseName" placeholder="请输入费用条目" />
                </el-form-item>
                <el-form-item label="预算金额" prop="expenseAmount">
                    <el-input v-model="formBudget.expenseAmount" placeholder="请输入预算金额" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitBudgetForm">保 存</el-button>
                <el-button @click="cancel">关 闭</el-button>
            </div>
        </el-dialog>
        <!-- 添加或修改【请填写功能名称】对话框 -->
        <el-dialog :title="titleSub" :visible.sync="openSub" width="900px" append-to-body>
            <el-form ref="formSub" :model="formSub" :rules="rulesSub" label-width="100px">
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="项目编号" prop="projectNumber" label-width="110px">
                            <el-input v-model="formSub.projectNumber" placeholder="请输入项目编号" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">

                        <el-form-item label="项目名称" prop="projectName" label-width="110px">
                            <el-input v-model="formSub.projectName" placeholder="请输入项目名称" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="费用" prop="cost" label-width="110px">
                            <el-input v-model="formSub.cost" placeholder="请输入费用" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="执行人" prop="executorName" label-width="110px">
                            <el-input v-model="formSub.executorName" placeholder="点击选择执行人" @focus="userShow(4)" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="外协公司" prop="outsourcingCompany" label-width="110px">
                            <el-input v-model="formSub.outsourcingCompany" placeholder="请输入外协公司" readonly="readonly"
                                @focus="enterprise" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="类型" prop="type" label-width="110px">
                            <el-select v-model="formSub.type" placeholder="请选择类型" style="width: 284px;">
                                <el-option v-for="dict in dict.type.sub_project_type" :key="dict.value"
                                    :label="dict.label" :value="dict.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="产品名称" prop="productName" label-width="110px">
                            <el-input v-model="formSub.productName" placeholder="点击选择产品" readonly="readonly"
                                @focus="selectProduct" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="创建人" prop="creationName" label-width="110px">
                            <el-input v-model="formSub.creationName" disabled="disabled" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="计划开始时间" prop="startTime" label-width="110px">
                            <el-date-picker clearable v-model="formSub.startTime" type="date" value-format="yyyy-MM-dd"
                                placeholder="请选择计划开始时间" style="width: 284px;">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="计划结束时间" prop="endTime" label-width="110px">
                            <el-date-picker clearable v-model="formSub.endTime" type="date" value-format="yyyy-MM-dd"
                                placeholder="请选择计划结束时间" style="width: 284px;">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="阶段" prop="subProjectStage" label-width="110px">
                            <el-input v-model="formSub.subProjectStage" placeholder="点击选择阶段" readonly="readonly"
                                @focus="selectStage(2)" style="width:678px" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitSubForm">保 存</el-button>
                <el-button @click="cancelSub">关 闭</el-button>
            </div>
        </el-dialog>
        <el-dialog title="选择产品" height="450" :visible.sync="openSubProduct" width="900px" append-to-body>
            <el-table ref="tableProduct" v-loading="loading" :data="productInfoList"
                @selection-change="handleSelectionChangeProjectProduct">
                <el-table-column type="selection" width="45" align="center" />
                <el-table-column label="产品类型" align="center" prop="productCategory">

                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.product_type" :value="scope.row.productCategory" />
                    </template>
                </el-table-column>
                <el-table-column label="产品编号" align="center" prop="productNumber" />
                <el-table-column label="产品名称" align="center" prop="productName" />
                <el-table-column label="费用" align="center" prop="pricingRange" />
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryProductParams.pageNum"
                :limit.sync="queryProductParams.pageSize" @pagination="getProjectProductList" />
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="saveProjectProduct">保 存</el-button>
            </div>
        </el-dialog>
        <el-dialog title="选择阶段" :visible.sync="openStage" width="55%">
            <div>
                <el-row>
                    <el-col>
                        <el-transfer filterable v-model="chooseRole" :render-content="renderFunc"
                            :titles="['全部阶段', '已选阶段']" filter-placeholder="请输入" :data="roleData"
                            @right-check-change="choose" target-order="push">
                        </el-transfer>
                    </el-col>
                    <el-col>
                        <el-button type="primary" plain @click="handleUp(index)"
                            style="margin: 5px 0px 0px 552px;">上移</el-button>
                        <el-button type="primary" plain @click="handleDown(index)"
                            style="margin: 5px 0px 0px 10px;">下移</el-button>
                    </el-col>
                </el-row>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeProjectStage">关 闭</el-button>
                <el-button type="primary" @click="saveProjectStage">保 存</el-button>
            </span>
        </el-dialog>
        <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
            <el-row>
                <el-col :span="5">
                    <MainType :typeCode="enterpriseCode" @getNode="getNodeEnterprise" :isTree="isTree"></MainType>
                </el-col>
                <el-col :span="19">
                    <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
                        v-show="showSearch" label-width="100px">
                        <el-form-item label="企业名称" prop="enterpriseName">
                            <el-input v-model="queryEnterpriseParams.enterpriseName" placeholder="请输入企业名称" clearable
                                @keyup.enter.native="handleQueryEnterprise" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini"
                                @click="handleQueryEnterprise">搜索</el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQueryEnterprise">重置</el-button>
                            <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
                        @selection-change="handleSelectionChangeEnterprise" :data="enterInfoList" highlight-current-row>
                        <el-table-column type="selection" width="45" align="center" />
                        <el-table-column label="企业名称" align="center" prop="enterpriseName" />
                        <el-table-column label="联系人" align="center" prop="contacts" />
                        <el-table-column label="联系电话" align="center" prop="telephone" show-overflow-tooltip="true" />
                    </el-table>
                    <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
                        :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
                </el-col>
            </el-row>
        </el-dialog>
    </div>
</template>

<script>
import { listProjectInfo, getProjectInfo, delProjectInfo, addProjectInfo, updateProjectInfo } from "@/api/project/projectInfo";
import { listBudget, getBudget, delBudget, addBudget, updateBudget } from "@/api/project/budget";
import { listReviewInfo, getReviewInfo, delReviewInfo, addReviewInfo, updateReviewInfo, saveProjectReview } from "@/api/project/review";
import { id } from "@/api/system/UUID";
import { listStage, getStage, delStage, addStage, updateStage } from "@/api/project/stage";
import { listSubInfo, getSubInfo, delSubInfo, addSubInfo, updateSubInfo } from "@/api/project/subInfo";
import { listType } from "@/api/maintype/type";
import { listInfo } from "@/api/enterprise/info";
import SelectUser from "../../system/role/selectUser.vue";
import Treeselect from "@riophae/vue-treeselect";
import MainType from "@/components/MainType/index"
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listMethod } from "@/api/project/method";
import { listProjectProductInfo, getProjectProductInfo, delProjectProductInfo, addProjectProductInfo, updateProjectProductInfo } from "@/api/project/projectProductInfo";
export default {
    name: "Info",
    components: { Treeselect, SelectUser, MainType },
    dicts: ['project_stage', 'business_classify', 'customer_industry', 'business_state', 'tracking_stage', 'enterprise_records', 'product_type', 'product_status', 'customer_industry', 'administrative_area', 'qualification_resume_status', 'contract_review_result', 'sub_project_type', 'sub_project_type'],
    props: {
        opt: {
            type: String,
            default: ""
        },
        newMarkAs: {
            type: String,
            default: ""
        },

        seas: {
            type: String,
            default: "0"
        },
        id: {
            type: String,
            default: ""
        },
        obj: {
            type: Object,
            default: null
        },
        //序号
        index: {
            type: Number,
            default: 0
        }
    },
    data() {
        var subOutsourcingCompany = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('外协公司不能为空'));
            }
            return callback()
        };
        var productName = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('产品名称不能为空'));
            }
            return callback()
        };
        var reviewer = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('评审人不能为空'));
            }
            return callback()
        };
        var mainExecutorName = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('项目执行人不能为空'));
            }
            return callback()
        };
        var subExecutorName = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('执行人不能为空'));
            }
            return callback()
        };
        var subProjectStage = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('阶段不能为空'));
            }
            return callback()
        };
        var projectStage = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('阶段不能为空'));
            }
            return callback()
        };
        return {
            eIds: [],
            eName: [],
            enterInfoList: [],
            isTree: false,
            enterpriseCode: "enterprise",
            open: false,
            pId: "",
            isOpt: false,
            pName: "",
            titleSub: "",
            isReview: true,
            openSubProduct: false,
            openSub: false,
            infoList: [],
            stageList: [],
            reviewView: true,
            isShowButton: true,
            isSelect: true,
            dateRange: [],
            tableData: [],
            budgetList: [],
            reviewList: [],
            openBudget: false,
            projectStageString: "",
            isSave: true,
            isDel: true,
            isView: false,
            pageSize: [5, 10, 20, 30, 50],
            isTree: false,
            qualificationList: [],
            total2: 0,
            total1: 0,
            openProduct: false,
            //产品列表
            productInfoList: [],
            stageProjectList: [],
            typeShow: true,
            radio: '1',
            readonly: true,
            checkCount: 0,
            UUID: '',
            userType: "1",
            optionData: null,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],

            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            //行政区域
            options: null,
            // 企业信息表格数据
            recordsList: [],
            businessId: new Date().getTime(),
            // 弹出层标题
            title: "",
            sign: '1',
            honorShow: '0',
            // 是否显示弹出层
            open: false,
            contractSum: 0,
            queryContractForm: {},
            // 查询参数
            queryParams: {
                enterpriseId: null,

            },
            //收款方式
            queryPaymentParams: {
                pageNum: 1,
                pageSize: 15,
                paymentId: null,
                projectId: null,
                paymentName: null,
                amountCollected: null,
                estimatedCollectionTime: null
            },
            querySubParams: {
                pageNum: 1,
                pageSize: 15,
                projectId: null,
                projectNumber: null,
                projectName: null,
                productId: null,
                productName: null,
                outsourcingCompany: null,
                executorId: null,
                executorName: null,
                cost: null,
                type: null,
                startTime: null,
                endTime: null,
                creationId: null,
                creationName: null,
                creationTime: null
            },
            //产品查询参数
            queryProductParams: {
                pageNum: 1,
                pageSize: 15,
                classificationId: null,
                projectId: null,
                productId: null,
                productCategory: null,
                productNumber: null,
                productName: null,
                pricingRange: null
            },
            //合同查询参数
            queryContractParams: {
                pageNum: 1,
                pageSize: 15,
                classificationId: null,
                contractName: null,
                budgetAmount: null,
                relatedContractId: null,
                relatedContractName: null,
                contractAmount: null,
                signingTime: null,
                endTime: null,
                enterpriseId: null,
                enterpriseName: null,
                customerAddress: null,
                customerContact: null,
                telephone: null,
                salespersonId: null,
                salespersonName: null,
                additionalTerms: null,
                belongTo: null,
                creationId: null,
                creationName: null,
                creationTime: null,
                operateTime: null,
                operateId: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                state: null
            },
            queryBudgetParams: {
                pageNum: 1,
                pageSize: 15,
                projectId: null,
                expenseName: null,
                expenseAmount: null,
                creationId: null,
                creationName: null,
                creationTime: null
            },
            queryReviewParams: {
                pageNum: 1,
                pageSize: 15,
                reviewId: null,
                projectId: null,
                reviewerId: null,
                reviewer: null,
                reviewComments: null,
                reviewTime: null,
                reviewResult: null
            },
            queryStageParams: {
                pageNum: 1,
                pageSize: 15,
                projectId: null,
                stageName: null
            },
            //产品查询参数
            queryProductListParams: {
                pageNum: 1,
                pageSize: 15,
                projectId: null,
                productId: null,
                productCategory: null,
                productNumber: null,
                productName: null,
                pricingRange: null
            },
            queryEnterpriseParams: {
                pageNum: 1,
                pageSize: 15,
                enterpriseName: null,
                enterpriseSource: null,
                enterpriseAbbreviation: null,
                administrativeArea: null,
                legalRepresentative: null,
                establishmentDate: null,
                contractAmount: null,
                enterpriseLabel: null,
                registeredCapital: null,
                industry: null,
                contacts: null,
                telephone: null,
                bankName: null,
                taxId: null,
                developmentId: null,
                transactionId: null,
                developmentManager: null,
                businessManager: null,
                enterpriseAddress: null,
                businessScope: null,
                enterpriseNature: null,
                markAs: '2',
                belongTo: null,
                creationTime: null,
                operateTime: null,
                operateId: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                classificationId: null
            },
            // 表单参数
            formReview: {
                reviewResult: 0,
                reviewComments: "同意"
            },
            formBudget: {},
            formSub: {},
            form: {
                creationName: this.$store.state.user.name,
                creationTime: this.parseTime(new Date(), '{y}-{m}-{d}'),
                classificationId: '650c44e1-b575-4b62-9d54-1ba9d1e8abb7',
                contractName: null
            },
            rulesSub: {

            },
            rulesBudget: {

            },
            reviewRules: {

            },
            // 表单校验
            rules: {
                executorName: [
                    { required: true, validator: mainExecutorName, trigger: "change" }
                ],
                projectStage: [
                    { required: true, validator: projectStage, trigger: "change" },
                ],
            },
            //复选框
            openStage: false,
            //选显卡默认选中
            activeName: 'first',
            //
            show: '',
            //上传按钮隐藏
            isShow: true,
            productIds: [],
            productNames: [],
            productTypes: [],
            productCodes: [],
            productRanges: [],
            contractList: [],
            openContract: false,
            contractName: null,
            contractId: null,
            porjectid: null,

            roleData: [],
            chooseRole: [],
            renderFunc(query, option) {

            },
            sort: '',
            item: '',
            value: '',
            stageString: '',
            typeInfo: 0
        };
    },
    watch: {
        obj(newVal) {
            this.form = newVal
            this.$forceUpdate();
        },
    },
    created() {
        this.listType();
        this.getSubList();
        this.getReviewList();
        this.getProjectProductList();
        this.getBudgetList();
        this.getStageList();
        this.getEnterpriseList();
        if (this.opt == "edit") {
            this.bId = this.id;
            this.handleUpdate(this.id)
        }
        if (this.opt == "mainView") {
            this.bId = this.id;
            this.isSave = false;
            this.isReview = false;
            this.reviewView = false;
            this.isShowButton = false;
            this.handleUpdate(this.id);
        }
    },
    methods: {
        dateOptions(time) {
            return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
        },
        saveSelectEnterprise() {
            if (this.eIds.toString() == "" || this.eIds.toString() == null) {
                this.$modal.msgError("请先选择客户！");
            } else {
                this.$set(this.formSub, 'outsourcingCompany', this.eName.toString())
                this.$set(this.formSub, 'outsourcingId', this.eIds.toString())
                this.closeOpen()
            }
        },
        handleQueryEnterprise() {
            this.queryEnterpriseParams.pageNum = 1;
            this.getEnterpriseList();
        },
        /** 重置按钮操作 */
        resetQueryEnterprise() {
            this.resetForm("queryFormEnterprise");
            this.handleQueryEnterprise();
        },
        closeOpen() {
            this.open = false;
        },
        getEnterpriseList() {
            this.loading = true;
            listInfo(this.queryEnterpriseParams).then(response => {
                this.enterInfoList = response.rows;
                this.total1 = response.total;
                this.loading = false;
            });
        },
        handleSelectionChangeEnterprise(selection) {
            if (selection.length > 1) {
                this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
                this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
            } else {
                this.eIds = selection.map(item => item.enterpriseId)
                this.eName = selection.map(item => item.enterpriseName)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            }
        },
        getNodeEnterprise(data, node, obj) {
            this.queryEnterpriseParams.classificationId = data.id
            this.getEnterpriseList()
        },
        enterprise() {
            this.open = true;
        },
        changeReviewComments() {
            if (this.formReview.reviewResult == '0') {
                this.formReview.reviewComments = "同意";
            } else {
                this.formReview.reviewComments = "";
            }
        },
        closeProjectStage() {
            this.openStage = false;
        },
        saveProjectStage() {
            this.stageString = "";
            var newAarry = this.chooseRole;
            var oldArray = this.roleData;
            if (newAarry.length > 0) {
                for (var i = 0; i < oldArray.length; i++) {
                    for (var j = 0; j < newAarry.length; j++) {
                        if (oldArray[i].key == newAarry[j]) {
                            this.stageString = this.stageString + oldArray[i].label + "→";
                        }
                    }
                }
                this.stageString = this.stageString.substring(0, this.stageString.lastIndexOf('→'));
                if (this.typeInfo == 1) {
                    if (this.form.projectStage != "" && this.form.projectStage != null) {
                        this.form.projectStage = "";
                        this.form.projectStage = this.stageString;
                    } else {
                        this.form.projectStage = this.stageString;
                    }
                } else if (this.typeInfo == 2) {
                    this.formSub.subProjectStage = this.stageString;
                }
                this.openStage = false;
            } else {
                this.$message.error("请先选择项目阶段！");
            }
        },
        getProjectStageList() {
            this.queryStageParams.projectId = this.id;
            listStage(this.queryStageParams).then(response => {
                this.stageProjectList = response.rows;
                var list = this.stageProjectList;
                if (list.length > 0) {
                    this.projectStageString = list[0].stageName;
                }
                this.form.projectStage = this.projectStageString;
            });
        },
        getStageList() {
            var roleData = [];
            this.stageList = this.dict.type.project_stage;
            var stages = this.stageList;
            setTimeout(function () {
                stages.forEach((stage, value) => {
                    roleData.push({
                        label: stage.label,
                        key: value,
                    });
                });
            }, 100)
            this.roleData = roleData;
        },
        //右侧选中
        choose(value) {
            let self = this
            self.item = value
        },
        //上移
        handleUp(item, value) {
            // item为选中的项，index为对应的index
            let self = this;
            item = self.item;
            if (item.length == 1) {
                self.chooseRole.find((val, indexs, arr) => {
                    if (val == item) {
                        value = indexs;
                    }
                });
                if (value == 0) {
                    //当选择的项的下标为0
                    self.$message("已经移到顶部");
                    return;
                }
                // 上移-改变的数组
                let changeItem = JSON.parse(JSON.stringify(self.chooseRole[value - 1]));
                self.chooseRole.splice(value - 1, 1);
                self.chooseRole.splice(value, 0, changeItem);
            } else {
                self.$message.error("只能选择一条数据上移");
                return;
            }

        },
        //下移
        handleDown(item, value) {
            let self = this;
            item = self.item;
            if (item.length == 1) {
                //选中值的下标
                self.chooseRole.find((val, indexs, arr) => {
                    if (val == item) {
                        value = indexs;
                    }
                });

                if (value == self.chooseRole.length - 1) {   // 这里是length-1,因为下标值从0开始
                    self.$message("已经移到底部");
                    return;
                }
                let changeItem = JSON.parse(JSON.stringify(self.chooseRole[value]));
                self.chooseRole.splice(value, 1);
                self.chooseRole.splice(value + 1, 0, changeItem);
            } else {
                self.$message.error("只能选择一条数据下移");
                return;

            }

        },
        // ***********************************
        selectStage(type) {
            this.typeInfo = type;
            this.getStageList();
            this.chooseRole = [];
            this.openStage = true;
        },
        getSubList() {
            this.loading = true;
            this.querySubParams.projectId = this.id;
            listSubInfo(this.querySubParams).then(response => {
                this.infoList = response.rows;
                this.loading = false;
            });
        },
        saveProjectProduct() {
            this.$set(this.formSub, 'productName', this.pName.toString())
            this.$set(this.formSub, 'productId', this.pId.toString())
            this.close()
        },
        handleSelectionChangeProjectProduct(selection) {
            if (selection.length > 1) {
                this.$refs.tableProduct.clearSelection(); // 清空所有选择
                this.$refs.tableProduct.toggleRowSelection(selection.pop()); // 设置选择项
            } else {
                this.pId = selection.map(item => item.id)
                this.pName = selection.map(item => item.productName)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            }
        },
        close() {
            this.openSubProduct = false;
        },
        selectProduct() {
            this.openSubProduct = true;
        },
        addSubProject() {
            this.resetSub();
            this.formSub.creationName = this.$store.state.user.name;
            this.titleSub = "添加子项目信息";
            this.openSub = true;
        },
        /** 删除按钮操作 */
        handleDeleteSub(row) {
            const ids = row.id
            this.$modal.confirm('是否确认删除项目名称为"' + row.projectName + '"的数据项？').then(function () {
                return delSubInfo(ids);
            }).then(() => {
                this.getSubList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        getReviewList() {
            this.loading = true;
            this.queryReviewParams.projectId = this.id;
            listReviewInfo(this.queryReviewParams).then(response => {
                this.reviewList = response.rows;
                this.loading = false;
            });
        },
        getBudgetList() {
            this.loading = true;
            this.queryBudgetParams.projectId = this.id;
            listBudget(this.queryBudgetParams).then(response => {
                this.budgetList = response.rows;
                this.loading = false;
            });
        },
        addBudgetInfo() {
            this.openBudget = true;
        },
        selectReviewUser() {
            this.userShow(3);
        },
        userShow(type) {
            this.show = type
            this.$refs.select.show();
        },
        //刪除已保存的項目產品
        handleDeleteProduct(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除产品名称为"' + row.productName + '"的数据信息？').then(function () {
                return delProjectProductInfo(ids);
            }).then(() => {
                this.getProjectProductList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        indexMethod(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        //查询選擇的产品信息列表 根據項目id查詢
        getProjectProductList() {
            this.loading = true;
            //this.queryProductParams.projectId =this.id
            if (this.opt == "add") {
                this.queryProductParams.projectId = this.UUID
                //this.bId = this.form.projectId;
            } else {
                this.queryProductParams.projectId = this.id
            }
            //alert(this.id)
            listProjectProductInfo(this.queryProductParams).then(response => {
                this.productInfoList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        getFile(data) {
            //console.log(JSON.stringify(data))
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
            this.$emit('change');
        },
        indexMethod(index) {
            return (this.queryProductParams.pageNum - 1) * this.queryProductParams.pageSize + index + 1;
        },
        indexMethodList(index) {
            return (this.queryProductListParams.pageNum - 1) * this.queryProductListParams.pageSize + index + 1;
        },
        indexMethodContractList(index) {
            return (this.queryContractParams.pageNum - 1) * this.queryContractParams.pageSize + index + 1;
        },
        selectUser(userId, userName) {
            if (this.show == '2') {//评审人
                this.$set(this.form, 'reviewer', userName)
                this.$set(this.form, 'reviewerId', userId)
            } else if (this.show == '1') {//负责人
                this.$set(this.form, 'projectLeader', userName)
                this.$set(this.form, 'projectLeaderId', userId)
            } else if (this.show == '3') {
                this.$set(this.formReview, 'reviewer', userName)
                this.$set(this.formReview, 'reviewerId', userId)
            } else if (this.show == '4') {
                this.$set(this.formSub, 'executorName', userName)
                this.$set(this.formSub, 'executorId', userId)
            } else if (this.show == '5') {
                this.$set(this.form, 'executorName', userName)
                this.$set(this.form, 'executorId', userId)
            }

        },
        //获取树节点数据
        listType() {
            listType({ typeCode: 'project' }).then(res => {
                this.optionData = res.data;
            })
        },
        selectOpen(type) {
            this.show = type
            this.$refs.select.show();
        },
        normalizer(node) {
            if (node.children && !node.children.length) {
                delete node.children;
            }
            return {
                id: node.areaId,
                label: node.areaName,
                isDisabled: node.parentId == '000000' ? true : false,
                children: node.list.length > 0 ? node.list : 0,
            }
        },
        /** 修改按钮操作 */
        handleUpdate(id) {
            this.reset();
            this.contractSum = 0;
            getProjectInfo(id).then(response => {
                this.form = response.data;
                if (this.form.executorName != "" && this.form.executorName != null) {
                    this.isReview = false;
                }
            });
            this.queryBudgetParams.projectId = id;
            listBudget(this.queryBudgetParams).then(response => {
                this.budgetList = response.rows;
                var list = this.budgetList;
                for (var i = 0; i < list.length; i++) {
                    this.contractSum = this.contractSum + list[i].expenseAmount;
                }
                this.form.budgetAmount = this.contractSum;
            });
            this.getProjectStageList();
            this.queryPaymentParams.projectId = id;
            listMethod(this.queryPaymentParams).then(response => {
                this.tableData = response.rows;
            });
        },
        submitSubForm() {
            if (new Date(this.formSub.endTime).getTime() < new Date(this.formSub.startTime).getTime()) {
                this.$message.error('计划开始时间不能大于计划结束时间！');
                return;
            }
            this.$refs["formSub"].validate(valid => {
                if (valid) {
                    this.formSub.projectId = this.id;
                    if (this.formSub.id != null) {
                        updateSubInfo(this.formSub).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getSubList();
                        });
                    } else {
                        this.formSub.id = this.guid();
                        addSubInfo(this.formSub).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.openSub = false;
                            this.getSubList();
                        });
                    }
                }
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    updateProjectInfo(this.form).then(response => {
                        this.$modal.msgSuccess("保存成功");
                        this.isReview = false;
                    });
                }
            });
        },
        submitBudgetForm() {
            this.$refs["formBudget"].validate(valid => {
                if (valid) {
                    this.formBudget.id = this.guid();
                    this.formBudget.projectId = this.id;
                    addBudget(this.formBudget).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.openBudget = false;
                        this.getBudgetList();
                    });
                }
            });
        },
        cancelSub() {
            this.resetSub();
            this.openSub = false;
        },
        submitReviewForm() {
            this.$refs["formReview"].validate(valid => {
                if (valid) {
                    const reviewInfo = {
                        reviewId: this.guid(),
                        projectId: this.id,
                        reviewResult: this.formReview.reviewResult,
                        reviewComments: this.formReview.reviewComments,
                        reviewerId: this.formReview.reviewerId,
                        reviewer: this.formReview.reviewer
                    }
                    saveProjectReview(reviewInfo).then(response => {
                        this.$modal.msgSuccess("新增成功");
                        this.open = false;
                        this.isOpt = true;
                        this.isShowButton = false;
                        this.isSelect = false;
                        this.getReviewList();
                    });
                }
            });
        },
        handleDeleteBudget(row) {
            const ids = row.id;
            this.$modal.confirm('是否确认删除费用条目为"' + row.expenseName + '"的数据项？').then(function () {
                return delBudget(ids);
            }).then(() => {
                this.getBudgetList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        getId() {
            id({}).then(response => {
                this.UUID = response.msg
                this.form.projectId = response.msg
                this.queryProductParams.projectId = response.msg;//项目id
            });
        },

        // 表单重置
        reset() {
            this.form = {
                projectId: null,
                projectType: null,
                node: null,
                classificationId: null,
                projectNumber: null,
                projectName: null,
                projectStage: null,
                contractId: null,
                contractName: null,
                budgetAmount: null,
                projectLeaderId: null,
                projectLeader: null,
                executorId: null,
                executorName: null,
                startTime: null,
                endTime: null,
                attackTime: null,
                completeTime: null,
                state: null,
                operateTime: null,
                operateId: null,
                operateName: null,
                departmentId: null,
                departmentName: null,
                organizationId: null,
                organizationName: null,
                creationId: null,
                creationName: null,
                creationTime: null,
                belongTo: null,
                delFlag: null
            };
            this.resetForm("form");
        },
        resetSub() {
            this.formSub = {
                id: null,
                projectId: null,
                projectNumber: null,
                projectName: null,
                productId: null,
                productName: null,
                subProjectStage: null,
                outsourcingId: null,
                outsourcingCompany: null,
                executorId: null,
                executorName: null,
                cost: null,
                type: null,
                startTime: null,
                endTime: null,
                creationId: null,
                creationName: null,
                creationTime: null
            };
            this.resetForm("formSub");
        },
        handleClick(tab, event) {
            if (tab.name == 'first') {
                this.handleUpdate(this.id)
            }
            if (tab.name == 'second') {

            }
            if (tab.name == 'third') {

            }
            if (tab.name == 'four') {

            }
        },
        guid() {
            function S4() {
                return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
            }
            return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
        },
    }
};
</script>

<style scoped lang="scss">
::v-deep .el-table .el-table__header-wrapper .el-checkbox {
    display: none;
}
</style>
